package com.iemes.controller.warehouse;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.iemes.annotation.SystemLog;
import com.iemes.controller.index.BaseController;
import com.iemes.entity.AnalyzeformFormMap;
import com.iemes.entity.EnterstorageFormMap;
import com.iemes.entity.OrderFormMap;
import com.iemes.entity.OvertimeanalyzeFormMap;
import com.iemes.entity.ReckonformFormMap;
import com.iemes.entity.ShapeProductionFormMap;
import com.iemes.entity.WarehouseStockFormMap;
import com.iemes.mapper.shape.ShapeMapper;
import com.iemes.mapper.warehouse.EnterstorageMapper;
import com.iemes.plugin.PageView;
import com.iemes.util.Common;
import com.iemes.util.DateUtils;
import com.iemes.util.MyDateUtils;

@RequestMapping("/enterstorage_form/")
@Controller
public class Enterstorage_FormController extends BaseController {

	@Inject
	private EnterstorageMapper enterstorageMapper;

	// 查看入库报表，显示按钮。
	@RequestMapping("enterstorage_form")
	public String enterstorage_form(Model model) {
		model.addAttribute("res", findByRes());
		return Common.BACKGROUND_PATH + "/warehouse/enterstorage_form_list";
	}

	// 入库报表分页
	@ResponseBody
	@RequestMapping("enterstorage_form_findByPage")
	public PageView findByPage(String pageNow, String pageSize) throws Exception {
		EnterstorageFormMap enterstorageFormMap = getFormMap(EnterstorageFormMap.class);
		List<Map<String, Object>> enter = enterstorageMapper.getAll(enterstorageFormMap);
		LuogicPaging(pageNow, pageSize, enter);
		return pageView;
	}

	// 编辑入库报表
	@RequestMapping("enterstorage_form_edit")
	public String editUI(Model model) throws Exception {
		String id = getPara("id");
		if(Common.isNotEmpty(id)){
			//根据id获得入库报表
			EnterstorageFormMap enter=enterstorageMapper.getById(id);
			model.addAttribute("enter",enter);
			
//			//获取入库报表用料
//			EnterstorageFormMap enterstorageFormMap = getFormMap(EnterstorageFormMap.class);
//			List<Map<String, Object>> process = enterstorageMapper.getEntryByPrstate(enterstorageFormMap);
//			for(Map<String, Object>map:process){
//				//获取今天用料
//				EntryFormMap entryFormMap=entryMapper.getTodaypur();
//				System.out.println("entryFormMap："+entryFormMap.get("name").toString());
//				System.out.println("Materials_Brand："+map.get("Materials_Brand").toString());
//				System.out.println("now_mold_encode："+map.get("now_mold_encode").toString());
//				System.out.println("prmold："+map.get("prmold").toString());
//				if(((entryFormMap.get("name").toString().equals(map.get("Materials_Brand").toString()))
//						&&((map.get("now_mold_encode").toString().equals(map.get("prmold").toString()))))){
////					process= enterstorageMapper.getEntryByPrstate(enterstorageFormMap);
//						model.addAttribute("process",process);
//				}
//			}
		}
		return Common.BACKGROUND_PATH + "/warehouse/enterstorage_form_edit";
	}

	// 修改入库报表
	@ResponseBody
	@RequestMapping(value = "enterstorage_form_editEntity")
	@Transactional(readOnly=false)//需要事务操作必须加入此注解
	@SystemLog(module = "入库报表", methods = "编辑入库报表-修改入库报表") // 凡需要处理业务逻辑的.都需要记录操作日志
	public String editEntity(HttpServletRequest request) throws Exception {
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date=new Date();
		EnterstorageFormMap enterstorageFormMap=getFormMap(EnterstorageFormMap.class);
		enterstorageFormMap.put("date", sdf.format(date));
		baseMapper.editEntity(enterstorageFormMap);
		return "success";
	}
}












